package cn.stronglink.assetmanage.business.task.view;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.view.View;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.stronglink.assetmanage.MyApplication;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.inventory.adapter.InventoryVpAdapter;
import cn.stronglink.assetmanage.business.task.adapter.TaskVpAdapter;

/**
 * 操作入库主fragment
 * Created by chencongcong on 2018/6/12.
 */

public class TaskView {
    private Fragment fragment;
    @BindView(R.id.tb_task)
    TabLayout tb_task;
    @BindView(R.id.vp_task)
    ViewPager vp_task;
    private String[] mTitle = {
            MyApplication.APP_CONTEXT.getResources().getString(R.string.task_wait),
            MyApplication.APP_CONTEXT.getResources().getString(R.string.task_operated),
            MyApplication.APP_CONTEXT.getResources().getString(R.string.check_wait_sync)
    };
    private TaskVpAdapter vpAdapter;
    private FragmentManager fm;
    public TaskView(Fragment fragment, View view) {
        this.fragment = fragment;
        ButterKnife.bind(this,view);
        initView();
    }

    private void initView() {
        fm = fragment.getChildFragmentManager();
        vpAdapter = new TaskVpAdapter(fm,mTitle);
        vp_task.setAdapter(vpAdapter);
        tb_task.setupWithViewPager(vp_task);
        tb_task.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                vp_task.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }
}
